<?php

$dp;

	$QRY = "SELECT * FROM message_in_out order by id_message_in_out asc";

	$cont = new GCD($QRY);

	/* varibale for filter/search */
	$_fldname = array("id_transaksi", "time_request", "jenis_transaksi", "bill_info1", "id_outlet", "id_biller","bill_info2","nominal");
	$_fldtampil = array("No Resi", "Tanggal / jam", "Jenis Transaksi", "via", "Agen Id", "Kode Supplier", "id pelanggan / tujuan", "Nominal");
	$_fldtype = array("text", "text", "text", "integer", "timestamp", "integer", "text", "text");



	require_once($__CFG_dir_lib . "filterpanel.php");
	$fp = new FilterPanel($url, $_fldname, $_fldtampil, $_fldtype);

	$whr = $fp->getFilterString();

	$action = $_REQUEST["act"];

	if($action=="rem" && $kode!="") {

		$cont->deleteData("message_in_out", "id_transaksi", $kode);
                
                $arrValsLog = array(date("Y-m-d H:i:s"), $auth->getUserID(), "Menghapus Data Transaksi dengan ID Transaksi ". $kode);  //"log_time", "log_aktor", "log_event"
                $cont->insertLog($arrValsLog);

	}elseif($action=="exp"){

		$QRYEXPORT = "SELECT 
			id_transaksi AS NO_RESI,
			time_request AS TANGGAL/JAM,
			jenis_transaksi AS JENIS_TRANSAKSI,
			bill_info1 AS VIA,
			id_outlet AS AGEND_ID,
			id_biller AS KODE_SUPPLIER, 
			bill_info2 AS ID_PELANGGAN/TUJUAN, 
			nominal AS NOMINAL, 
			response_code AS RESPONSE_CODE, 
			status AS STATUS 
			FROM message_in_out";

                $QRYEXPORT = $QRYEXPORT . ($whr != ""? " where ". $whr : "");

                $arrValsLog = array(date("Y-m-d H:i:s"), $auth->getUserID(), "Export Data History Transaksi ");  //"log_time", "log_aktor", "log_event"
                $cont->insertLog($arrValsLog);

		$filename = $__CFG_dir_export . $auth->getUserID() .".csv";

		$cmd = "touch $filename";
		shell_exec($cmd);
	
			
		$cmd = "chmod 0777 $filename";
		shell_exec($cmd);

		$cmd = "psql -U". $__CFG_dbuser ." ". $__CFG_dbname ." -c  \"COPY (". $QRYEXPORT .") TO '". $filename ."' WITH CSV HEADER\"";
		shell_exec($cmd);
		
		echo "<script>window.open('". $__CFG_http_export . $auth->getUserID() .".csv', 'wndStaff', 'width=730,height=500,directories=0,location=0,resizable=1,scrollbars=1,toolbar=0,copyhistory=0,status=0')</script>";

	}


$cont->getResultSet($whr, "", $sc_pageslimit);


setPageTitle("History Transaksi");
require_once($__CFG_dir_adminlayout . $__CFG_site_adminlayout."/header.php");

$gb = new GB();


?>

<br />

<div id="maincontent">
<h3>History Pengguna</h3>

<script language="javascript">
function removeData(kode) {

	if(confirm('Anda yakin akan menghapus data ini?')) {
		location.href = '<?php echo $__CFG_http_root; ?>index.php/history/history_transaksi/' + kode + '/?act=rem';
	}
}

function detil(kode){
        return GB_showCenter('Data Transaksi', '<?php echo $__CFG_http_root; ?>index.php/popup/log_user/'+ kode, 500, 850);
}

function exportData(){
	location.href = '<?php echo $__CFG_http_root; ?>index.php/history/history_transaksi/?act=exp&<?php echo $_SERVER["QUERY_STRING"]?>';
}
</script>



<div class="DivTable">
<div class="box-control">
<?php
$gb->createLink($__CFG_http_root."index.php/history/history_transaksi/", "", "Tambah Data", "add");
echo "<a href=\"#\" onclick=\"javascript:exportData()\" class=\"report\" title=\"Export Data\">&nbsp;</a>";
echo "<a href=\"#\" class=\"search\" title=\"Cari Data\">&nbsp;</a>";
echo "<a href=\"". $__CFG_http_root."index.php/history/history_transaksi\" class=\"refresh\" title=\"Muat Ulang\">&nbsp;</a>";
?>
</div>

<table class="GridTable">

<!--  ************   begin form search ****************** -->
<tr class="form-search">
<td colspan="8">    
<?php echo $fp->drawfilterpanel("", $_fldname, $_fldtampil, $_fldtype)?>
</td>
</tr>
<!-- ************   end form search ********************* -->

<tr class="GridHeader">
<td width="20">No.</td>
<td>&nbsp;</td>

<td>No Id</td>
<td>Agen</td>
<td>Waktu</td>
<td>via</td>
<td>Nama</td>
<td>Type</td>
<td>Pesan</td>

</tr>

<?php


//debugQuery($POST, TRUE);

if($cont->countListData() > 0) {
	$nomor = $i;
	foreach($cont->listData() as $row) {
		$nomor++;


		$kodecontent = $row->id_message_in_out;

		$styleTR = "GridItem1";

		?>
			<tr class="<?php echo  $styleTR;?>" >
			<td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo  $nomor;?></td>
			<td>
			<?php
			//$gb->createLink($__CFG_http_root."index.php/history/history_transaksi/". $kodecontent ."", "", "Ubah Data", "edit");
		echo "<a href=\"#\" class=\"delete\" title=\"Hapus Data\" onclick=\"javascript:removeData('". $kodecontent ."')\">&nbsp;</a>";
		?>

			</td>
			<td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo  $row->id_message_in_out;?></td>
			<td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo  $row->sender;?></td>
			<td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo  $row->date_created;?></td>
			<td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo  $row->via;?></td>
			<td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo  $row->receiver;?></td>
			<td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo  $row->is_sent;?></td>
			<td onclick="javascript:detil('<?php echo $kodecontent; ?>')"><?php echo  $row->content;?></td>
			</tr>	
			<?php
	}

}
else {
	?>
		<tr class="GridItem1">
		<td colspan="20">Tidak ada data</td>
		</tr>	

		<?php
}

?>
</table>
</div>
<?php //echo $pg->createPage($countdata, $offset, $limit, $nextPage, $pagePerCols, $colPage); ?>
<br class="bersih" />

</div>

<script type="text/javascript">

function openURL(url) {
	open(''+ url +'', 'wndStaff', 'width=730,height=500,directories=0,location=0,resizable=1,scrollbars=1,toolbar=0,copyhistory=0,status=0');
        return false;
}

jQuery(document).ready(function(){
		jQuery(".form-search").hide();

		jQuery('.search').click(
			function(){
			jQuery(".form-search").slideToggle();
			}
			);

		});

</script>
